package com.uroad.lib.application;

import android.app.Activity;
import android.app.Application;

import com.uroad.lib.imageloader.ImageLoaderHelper;

import java.util.LinkedList;
import java.util.List;

public class BaseApplication extends Application {

	private List<Activity> activitys = new LinkedList<Activity>();
	public static ImageLoaderHelper imgHelper = null;

	@Override
	public void onCreate() {
		super.onCreate();
		imgHelper = ImageLoaderHelper.getInstance();
	}

	/**
	 * 注册activity
	 * 
	 * @param activity
	 */
	public void registerActivity(Activity activity) {
		activitys.add(activity);
	}
	
	public void unRegisterActivity(Activity activity) {
		activitys.remove(activity);
	}

	/**
	 * 关闭所有的Activity
	 */
	public void finishActivities() {
		for (Activity a : activitys) {
			if (null != a && !a.isFinishing()) {
				a.finish();
			}
		}
	}

	/**
	 * 退出整个APP
	 */
	public void exit() {
		this.finishActivities();
		android.os.Process.killProcess(android.os.Process.myPid());
	}
}
